Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
es-get-iterator
Advanced tools
Get an iterator for any JS language value. Works robustly across all environments, all versions.
The es-get-iterator package is a utility for retrieving an iterator from a given object, array, string, or other iterable types in JavaScript. It abstracts away the differences between various iterable protocols and provides a unified way to iterate over values in different types of collections.
Getting an iterator from an array
This feature demonstrates how to retrieve an iterator from an array and use it to access the first element.
const getIterator = require('es-get-iterator');
const array = [1, 2, 3];
const iterator = getIterator(array);
console.log(iterator.next().value); // 1
Getting an iterator from a string
This feature shows how to get an iterator from a string to iterate over its characters.
const getIterator = require('es-get-iterator');
const string = 'hello';
const iterator = getIterator(string);
console.log(iterator.next().value); // 'h'
Getting an iterator from a Map
This example demonstrates retrieving an iterator from a Map object to iterate over its key-value pairs.
const getIterator = require('es-get-iterator');
const map = new Map([[1, 'one'], [2, 'two']]);
const iterator = getIterator(map);
console.log(iterator.next().value); // [1, 'one']
Iterall is a package that provides utilities for working with JavaScript iteration protocols. It offers similar functionality to es-get-iterator by allowing users to work with iterable objects in a consistent manner. However, iterall focuses more on providing a set of utilities for managing iterables rather than just retrieving iterators.
Lodash is a comprehensive utility library that, among its vast array of functionalities, includes methods for iterating over collections such as arrays, objects, and strings. While not exclusively focused on iteration like es-get-iterator, lodash offers more general-purpose utilities that can be used in conjunction with or as an alternative to es-get-iterator for certain use cases.
Get an iterator for any JS language value. Works robustly across all environments, all versions.
In modern engines, value[Symbol.iterator]()
is sufficient to produce an iterator (an object with a .next
method) for that object. However, older engines:
Symbol
support altogetherSymbol.iterator
but not implement it on everything it should, like arguments objectsMap
and Set
, but a non-standard name for the iterator-producing method (.iterator
or ['@@iterator']
, eg)es6-shim
or core-js
or similarThis library attempts to provide an abstraction over all that complexity!
In node v13+, exports
is used to provide a lean implementation that lacks all the complexity described above, in combination with the browser
field so that bundlers will pick up the proper implementation.
If you are targeting browsers that definitely all have Symbol support, then you can configure your bundler to replace require('has-symbols')()
with a literal true
, which should allow dead code elimination to reduce the size of the bundled code.
@rollup/plugin-replace
// rollup.config.js
import replace from '@rollup/plugin-replace';
export default {
...
plugins: [
replace({
"require('has-symbols')()": 'true',
delimiters: ['', '']
})
]
};
var getIterator = require('es-get-iterator');
var assert = require('assert');
var iterator = getIterator('a 💩');
assert.deepEqual(
[iterator.next(), iterator.next(), iterator.next(), iterator.next()],
[{ done: false, value: 'a' }, { done: false, value: ' ' }, { done: false, value: '💩' }, { done: true, value: undefined }]
);
var iterator = getIterator([1, 2]);
assert.deepEqual(
[iterator.next(), iterator.next(), iterator.next()],
[{ done: false, value: 1 }, { done: false, value: 2 }, { done: true, value: undefined }]
);
var iterator = getIterator(new Set([1, 2]));
assert.deepEqual(
[iterator.next(), iterator.next(), iterator.next()],
[{ done: false, value: 1 }, { done: false, value: 2 }, { done: true, value: undefined }]
);
var iterator = getIterator(new Map([[1, 2], [3, 4]]));
assert.deepEqual(
[iterator.next(), iterator.next(), iterator.next()],
[{ done: false, value: [1, 2] }, { done: false, value: [3, 4] }, { done: true, value: undefined }]
);
Simply clone the repo, npm install
, and run npm test
v1.1.3 - 2023-01-12
c97cb76
node/install
instead of node/run
; use codecov
action 6d09911
npmignore
to autogenerate an npmignore file c7e0e85
eslint
, @ljharb/eslint-config
, aud
, auto-changelog
, es5-shim
, object-inspect
, tape
1353190
stop-iteration-iterator
ab19956
eslint
, @ljharb/eslint-config
, aud
, auto-changelog
, es5-shim
, object-inspect
, safe-publish-latest
, tape
de2ae73
e059f33
c8ffcec
eslint
, @ljharb/eslint-config
, aud
, es5-shim
, has-bigints
, object-inspect
, tape
8cd2e87
eslint
, @ljharb/eslint-config
, aud
, object-inspect
, tape
7676030
bdbe6c9
@ljharb/eslint-config
, aud
, es6-shim
67cddd6
a726fdc
has-symbols
, is-arguments
, is-string
044907b
get-intrinsic
, has-symbols
e492f8f
prepublishOnly
script for npm 7+ eccda6b
object-inspect
c24dfa5
get-intrinsic
1bd68ce
FAQs
Get an iterator for any JS language value. Works robustly across all environments, all versions.
The npm package es-get-iterator receives a total of 11,400,192 weekly downloads. As such, es-get-iterator popularity was classified as popular.
We found that es-get-iterator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.